package com.chf.job.controller;

import com.chf.job.common.Const;
import com.chf.job.common.ServerResponse;
import com.chf.job.pojo.Company;
import com.chf.job.pojo.Founder;
import com.chf.job.pojo.User;
import com.chf.job.service.CompanyService;
import com.chf.job.service.FounderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
public class FounderController {
    @Autowired
    private FounderService founderService;
    @Autowired
    private CompanyService companyService;

    /**
     * 添加公司创始人
     */
    @RequestMapping(value = "founder/addFounder.html", method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse addFounder(Founder founder, HttpServletRequest request) {
        User user = (User) request.getSession(true).getAttribute(Const.CURRENT_USER);
        Company company = companyService.getByEmail(user.getEmail());
        int result = founderService.addFounder(company.getId(), founder);
        if (result > 0) {
            return ServerResponse.createBySuccess("添加成功",Const.ADD_COMPANY);
        }
        return ServerResponse.createByErrorMessage("添加失败");
    }

}
